<?php
/**
 * Custom View class
 */
class CustomView extends View
{

    public $headerVars = false;

    public function top()
    {
        // Header vars
        $this->headerVars = $this->controller->getHeaderVars();
        $this->setTemplate('core', $this->defaultDir.'core');
        $this->parse('core', $this->headerVars);
        // Mobile?
        {
            $detect = new Mobile_Detect();
            if (($detect->isMobile() || $detect->isTablet()) && ((empty($this->headerVars['is_logged_in'])) || ($this->headerVars['user_data']['user_type'] == USER_TYPE_NORMAL)))
            {
                $this->parse('mobile_css');
            }
        }
        // Header
        $this->parse('core', $this->headerVars);
        {
            // Not logged in
            if (empty($this->headerVars['is_logged_in']))
            {
                $this->parse('header_not_logged_in', $this->headerVars);
            }
            else
            {
                $this->parse('header_logged_in', $this->headerVars);
            }
        }
        $this->parse('core', $this->headerVars);
        {
            // Menu
            switch($this->headerVars['user_data']['user_type'])
            {
                case USER_TYPE_ADMIN:
                    $this->parse('admin_menu', $this->headerVars);
                    break;
                case USER_TYPE_SECURITY_MANAGER:
                    $this->parse('security_menu', $this->headerVars);
                    break;
                case USER_TYPE_MASTER:
                    $this->parse('master_menu', $this->headerVars);
                    break;
            }
        }
        $this->parse('core', $this->headerVars);
    }

    public function bottom()
    {
        $this->setTemplate('core', $this->defaultDir.'core');
        // Notices
        $notices = $this->controller->getNotices();
        $vars    = false;
        if (!empty($notices))
        {
            $vars = array('dialog_on' => 'dialog_on');
        }
        $this->parse('core', $vars);
        // Messages type
        {
            if (!empty($notices))
            {
                $totalLengh = count($notices);
                $errsLength = 0;
                $notiLength = 0;
                foreach ($notices as $notice)
                {
                    if ($notice['type'] == MESSAGE_TYPE_ERROR)
                    {
                        $errsLength++;
                    }
                    else
                    {
                        $notiLength++;
                    }
                }
                if ($errsLength == $totalLengh)
                {
                    $this->parse('dialog_title_error');
                }
                else
                {
                    $this->parse('dialog_title_notice');
                }
            }
            else
            {
                $this->parse('dialog_title_notice');
            }
        }
        $this->parse('core', $vars);
        {
            if (!empty($notices))
            {
                foreach ($notices as $type => $notice)
                {

                    $this->parse('notice', array('notice' => $notice['message'], 'dialog_type' => ($notice['type'] == MESSAGE_TYPE_ERROR)?'error':''));
                }
            }
        }
        $this->parse('core');
        {
            if (!empty($this->headerVars['permisos']))
            {
                foreach ($this->headerVars['permisos'] as $accion => $permiso)
                {
                    $parse = array('accion' => $accion, 'permiso' => intval($permiso));
                    $this->parse('accion_set', $parse);
                }
            }
        }
        $this->parse('core');
    }

}
?>